package com.PAT.practice01;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/11/15/13:06
 * @Description: 读入 n（>0）名学生的姓名、学号、成绩，分别输出成绩最高和成绩最低学生的姓名和学号。
 * @Target: 成绩排名
 */
public class 成绩排名 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Student[] students = new Student[n];

        int MaxGrade = Integer.MIN_VALUE;
        int MaxNum = 0;
        int MinGrade = Integer.MAX_VALUE;
        int MinNum = 0;


        for (int i = 0; i < n; i++) {
          Student student = new Student();
            student.name = scanner.next();
            student.id = scanner.next();
            student.grade = scanner.nextInt();

            // 记录最大最小的编号
            while (MaxGrade<student.grade){
                MaxGrade = student.grade;
                MaxNum = i;
            }
            while (MinGrade>student.grade){
                MinGrade = student.grade;
                MinNum = i;
            }

            students[i] = student;

        }

        System.out.println("默认顺序:");
        for (Student student : students) {
            System.out.print(student+" ");
        }


        System.out.println();


        Arrays.sort(students,new MyCompara());
        System.out.println("排序后:");
        for (Student student : students) {
            System.out.print(student+" ");
        }
        System.out.println();




        System.out.println("最大:"+students[MaxNum].toString());
        System.out.println("最小:"+students[MinNum].toString());


    }



    public static class MyCompara implements Comparator<Student>{
        @Override
        public int compare(Student o1, Student o2) {
            return o1.getGrade()- o2.getGrade();
        }
    }






    static class Student{
        private String name;
        private String id;
        private int grade;

        public Student() {
        }

        public Student(String name, String id, int grade) {
            this.name = name;
            this.id = id;
            this.grade = grade;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "name='" + name + '\'' +
                    ", id='" + id + '\'' +
                    ", grade=" + grade +
                    '}';
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public int getGrade() {
            return grade;
        }

        public void setGrade(int grade) {
            this.grade = grade;
        }
    }


}
